/*
 * Copyright (c) 2009-2024 Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the License); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*============================ INCLUDES ======================================*/

#if defined(_RTE_)
#   include "RTE_Components.h"
#endif

#if defined(RTE_Acceleration_Arm_2D_Helper_PFB)

#include "arm_2d.h"

#ifdef RTE_Acceleration_Arm_2D_Scene4

#define __USER_SCENE4_IMPLEMENT__
#include "arm_2d_scene_4.h"
#include "arm_2d_scenes.h"
#include "arm_2d_helper.h"
#include "arm_2d_example_controls.h"

#include <stdlib.h>
#include <string.h>

#if defined(__clang__)
#   pragma clang diagnostic push
#   pragma clang diagnostic ignored "-Wunknown-warning-option"
#   pragma clang diagnostic ignored "-Wreserved-identifier"
#   pragma clang diagnostic ignored "-Wsign-conversion"
#   pragma clang diagnostic ignored "-Wpadded"
#   pragma clang diagnostic ignored "-Wcast-qual"
#   pragma clang diagnostic ignored "-Wcast-align"
#   pragma clang diagnostic ignored "-Wmissing-field-initializers"
#   pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#   pragma clang diagnostic ignored "-Wmissing-prototypes"
#   pragma clang diagnostic ignored "-Wunused-variable"
#   pragma clang diagnostic ignored "-Wgnu-statement-expression"
#   pragma clang diagnostic ignored "-Wdeclaration-after-statement"
#   pragma clang diagnostic ignored "-Wunused-function"
#   pragma clang diagnostic ignored "-Wmissing-declarations"  
#elif __IS_COMPILER_ARM_COMPILER_5__
#   pragma diag_suppress 64,177
#elif __IS_COMPILER_IAR__
#   pragma diag_suppress=Pa089,Pe188,Pe177,Pe174
#elif __IS_COMPILER_GCC__
#   pragma GCC diagnostic push
#   pragma GCC diagnostic ignored "-Wformat="
#   pragma GCC diagnostic ignored "-Wpedantic"
#   pragma GCC diagnostic ignored "-Wunused-function"
#   pragma GCC diagnostic ignored "-Wunused-variable"
#   pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
#endif

/*============================ MACROS ========================================*/

#if __GLCD_CFG_COLOUR_DEPTH__ == 8

#   define c_tileCMSISLogo          c_tileCMSISLogoGRAY8

#elif __GLCD_CFG_COLOUR_DEPTH__ == 16

#   define c_tileCMSISLogo          c_tileCMSISLogoRGB565

#elif __GLCD_CFG_COLOUR_DEPTH__ == 32

#   define c_tileCMSISLogo          c_tileCMSISLogoCCCA8888
#else
#   error Unsupported colour depth!
#endif

/*============================ MACROFIED FUNCTIONS ===========================*/
#undef this
#define this (*ptThis)

/*============================ TYPES =========================================*/
/*============================ GLOBAL VARIABLES ==============================*/

extern const arm_2d_tile_t c_tileCMSISLogo;
extern const arm_2d_tile_t c_tileCMSISLogoMask;
extern const arm_2d_tile_t c_tileCMSISLogoA2Mask;
extern const arm_2d_tile_t c_tileCMSISLogoA4Mask;

void draw_my_maze(void *pTarget,                                  
                 const arm_2d_tile_t *ptTile,                   
                 bool bIsNewFrame);
								 
void maze_play_task(arm_2d_scene_t *ptScene);								 
/*============================ PROTOTYPES ====================================*/
/*============================ LOCAL VARIABLES ===============================*/

/*! define dirty regions */
IMPL_ARM_2D_REGION_LIST(s_tDirtyRegions, static)

    /* a dirty region to be specified at runtime*/
    ADD_REGION_TO_LIST(s_tDirtyRegions,
        0  /* initialize at runtime later */
    ),
    
    /* add the last region:
        * it is the top left corner for text display 
        */
    ADD_LAST_REGION_TO_LIST(s_tDirtyRegions,
        .tLocation = {
            .iX = 0,
            .iY = 0,
        },
        .tSize = {
            .iWidth = 320,
            .iHeight = 240,
        },
    ),

END_IMPL_ARM_2D_REGION_LIST(s_tDirtyRegions)

/*============================ IMPLEMENTATION ================================*/

static void __on_scene4_load(arm_2d_scene_t *ptScene)
{
    user_scene_4_t *ptThis = (user_scene_4_t *)ptScene;
    ARM_2D_UNUSED(ptThis);

}

static void __on_scene4_depose(arm_2d_scene_t *ptScene)
{
    user_scene_4_t *ptThis = (user_scene_4_t *)ptScene;
    ARM_2D_UNUSED(ptThis);
    
    ptScene->ptPlayer = NULL;
    
    /* reset timestamp */
    arm_foreach(int64_t,this.lTimestamp, ptItem) {
        *ptItem = 0;
    }

    if (!this.bUserAllocated) {
        __arm_2d_free_scratch_memory(ARM_2D_MEM_TYPE_UNSPECIFIED, ptScene);
    }
}

/*----------------------------------------------------------------------------*
 * Scene 4                                                                    *
 *----------------------------------------------------------------------------*/

static void __on_scene4_background_start(arm_2d_scene_t *ptScene)
{
    user_scene_4_t *ptThis = (user_scene_4_t *)ptScene;
    ARM_2D_UNUSED(ptThis);

}

static void __on_scene4_background_complete(arm_2d_scene_t *ptScene)
{
    user_scene_4_t *ptThis = (user_scene_4_t *)ptScene;
    ARM_2D_UNUSED(ptThis);

}


static void __on_scene4_frame_start(arm_2d_scene_t *ptScene)
{
    user_scene_4_t *ptThis = (user_scene_4_t *)ptScene;
    ARM_2D_UNUSED(ptThis);

}

static void __on_scene4_frame_complete(arm_2d_scene_t *ptScene)
{
    user_scene_4_t *ptThis = (user_scene_4_t *)ptScene;
    ARM_2D_UNUSED(ptThis);
     maze_play_task( ptScene);
    /* switch to next scene after 3s */
    if (arm_2d_helper_is_time_out(3000, &this.lTimestamp[0])) {
        //arm_2d_scene_player_switch_to_next_scene(ptScene->ptPlayer);
    }
}

static void __before_scene4_switching_out(arm_2d_scene_t *ptScene)
{
    user_scene_4_t *ptThis = (user_scene_4_t *)ptScene;
    ARM_2D_UNUSED(ptThis);

}

static
IMPL_PFB_ON_DRAW(__pfb_draw_scene4_handler)
{
    user_scene_4_t *ptThis = (user_scene_4_t *)pTarget;
    arm_2d_size_t tScreenSize = ptTile->tRegion.tSize;

    ARM_2D_UNUSED(ptTile);
    ARM_2D_UNUSED(bIsNewFrame);
    ARM_2D_UNUSED(tScreenSize);
    
    arm_2d_canvas(ptTile, __top_canvas) {
    /*-----------------------draw the foreground begin-----------------------*/
        
        /* following code is just a demo, you can remove them */
        
        arm_2d_fill_colour(ptTile, NULL, GLCD_COLOR_BLACK);

      
        draw_my_maze(pTarget,                                  
                 ptTile,                   
                  bIsNewFrame);

    

        /* draw text at the top-left corner */

        arm_lcd_text_set_target_framebuffer((arm_2d_tile_t *)ptTile);
        arm_lcd_text_set_font(&ARM_2D_FONT_6x8.use_as__arm_2d_font_t);
        arm_lcd_text_set_draw_region(NULL);
        arm_lcd_text_set_colour(GLCD_COLOR_RED, GLCD_COLOR_WHITE);
        arm_lcd_text_location(0,0);
        arm_lcd_puts("Scene 4");

    /*-----------------------draw the foreground end  -----------------------*/
    }
    arm_2d_op_wait_async(NULL);

    return arm_fsm_rt_cpl;
}

ARM_NONNULL(1)
user_scene_4_t *__arm_2d_scene4_init(   arm_2d_scene_player_t *ptDispAdapter, 
                                        user_scene_4_t *ptThis)
{
    bool bUserAllocated = false;
    assert(NULL != ptDispAdapter);

    s_tDirtyRegions[dimof(s_tDirtyRegions)-1].ptNext = NULL;

    /* get the screen region */
    arm_2d_region_t tScreen
        = arm_2d_helper_pfb_get_display_area(
            &ptDispAdapter->use_as__arm_2d_helper_pfb_t);

    /* initialise dirty region 0 at runtime
     * this demo shows that we create a region in the centre of a screen(320*240)
     * for a image stored in the tile c_tileCMSISLogoMask
     */
    //arm_2d_align_centre(tScreen, c_tileCMSISLogoMask.tRegion.tSize) {
        //s_tDirtyRegions[0].tRegion = __centre_region;
    //}

    //s_tDirtyRegions[dimof(s_tDirtyRegions)-1].tRegion.tSize.iWidth 
    //                                                    = tScreen.tSize.iWidth;
    
    if (NULL == ptThis) {
        ptThis = (user_scene_4_t *)
                    __arm_2d_allocate_scratch_memory(   sizeof(user_scene_4_t),
                                                        __alignof__(user_scene_4_t),
                                                        ARM_2D_MEM_TYPE_UNSPECIFIED);
        assert(NULL != ptThis);
        if (NULL == ptThis) {
            return NULL;
        }
    } else {
        bUserAllocated = true;
    }
    memset(ptThis, 0, sizeof(user_scene_4_t));

    *ptThis = (user_scene_4_t){
        .use_as__arm_2d_scene_t = {

            /* the canvas colour */
            .tCanvas = {GLCD_COLOR_WHITE}, 

            /* Please uncommon the callbacks if you need them
             */
            .fnOnLoad       = &__on_scene4_load,
            .fnScene        = &__pfb_draw_scene4_handler,
            .ptDirtyRegion  = (arm_2d_region_list_item_t *)s_tDirtyRegions,
            

            //.fnOnBGStart    = &__on_scene4_background_start,
            //.fnOnBGComplete = &__on_scene4_background_complete,
            .fnOnFrameStart = &__on_scene4_frame_start,
            //.fnBeforeSwitchOut = &__before_scene4_switching_out,
            .fnOnFrameCPL   = &__on_scene4_frame_complete,
            .fnDepose       = &__on_scene4_depose,

            .bUseDirtyRegionHelper = false,
        },
        .bUserAllocated = bUserAllocated,
    };

    /* ------------   initialize members of user_scene_4_t begin ---------------*/


    /* ------------   initialize members of user_scene_4_t end   ---------------*/

    arm_2d_scene_player_append_scenes(  ptDispAdapter, 
                                        &this.use_as__arm_2d_scene_t, 
                                        1);

    return ptThis;
}


//=============================================================================================
extern uint16_t key_num ;

#define MAZE_DATA_H_NUM        23
#define MAZE_DATA_L_NUM        18
#define MAZE_LINE_WIDTH_HIGH   5
#define MAZE_PEOPLE_WIDTH      10
#define R_BRIGHT 20

#define R_BRIGHT_COLOR GLCD_COLOR_BLUE
#define MAZE_EXIT_COLOR GLCD_COLOR_RED
#define PEOPLE_COLOR 0xc94e
#define MAZE_INTERSECTION_COLOR 0xf810

arm_2d_region_t tPeopleRegion = 
{
    //.tLocation = {.iX = 206,.iY = 70,},.tSize = {.iWidth = 10, .iHeight = 10  },    //1
	 .tLocation = {.iX = 220,.iY = 2,},.tSize = {.iWidth = 10, .iHeight = 10  },    //1		
};

uint8_t maze_data_H[][3]={
{36,11,100},{198,14,240},{196,32,240},{0,26,102},{17,47,64},{122,48,159},{43,69,84},{140,68,176},{42,91,103},{122,90,173},
{17,117,101},{119,116,196},{0,138,103},{184,140,201},{17,154,83},{17,169,68},{71,186,82},{36,204,89},{187,157,220},{186,178,220},
{120,191,154},{138,206,220},{37,223,220},{0,0,0},};//23----------------
uint8_t maze_data_L[][3]={{17,0,25},{152,0,28},{17,48,117},{103,27,91},{122,14,90},{178,21,47},{196,50,117},{220,49,223},{17,155,240},{54,169,192},
{37,186,204},{82,155,208},{103,138,223},{120,117,168},{120,207,223},{136,133,191},{153,117,169},{170,135,187},};//18|||||||||
/*============================ PROTOTYPES ====================================*/
/*============================ LOCAL VARIABLES ===============================*/
char green_line_H[10] = {0};    
char green_line_L[10] = {0};   
static char people_moving_direction = 0;

void updata_dirty_regions();

#define		PIN_DIRECTION_RIGHT  6
#define		PIN_DIRECTION_DOWN   8
#define		PIN_DIRECTION_LEFT   4
#define		PIN_DIRECTION_UP     2
#define		PIN_DIRECTION_CTRL   3
#define 	PIN_DIRECTION_KEY_A  10 
#define 	PIN_DIRECTION_KEY_B  17 
#define 	PIN_DIRECTION_KEY_X  19 
#define 	PIN_DIRECTION_KEY_Y  21

void find_maze_line(){
    arm_2d_region_t ptRegionIn0 ={ 
                    .tLocation = {.iX = tPeopleRegion.tLocation.iX - R_BRIGHT,
                                  .iY = tPeopleRegion.tLocation.iY - R_BRIGHT,},
                    .tSize = {.iWidth = R_BRIGHT + MAZE_PEOPLE_WIDTH + R_BRIGHT ,
                              .iHeight = R_BRIGHT + MAZE_PEOPLE_WIDTH + R_BRIGHT  },  };
    arm_2d_region_t ptRegionIn1 = {.tLocation = {.iX = 0,.iY = 0,},.tSize = {.iWidth = 0, .iHeight = MAZE_LINE_WIDTH_HIGH  }};
    arm_2d_region_t ptRegionOut;
    char i = 0, j = 0;
    for(i = 0; i < 10; i++){
        green_line_H[i] = 0;
        green_line_L[i] = 0;
    } 
    for(i = 0;  i < MAZE_DATA_H_NUM; i++){
        ptRegionIn1.tLocation.iX = maze_data_H[i][0];
        ptRegionIn1.tLocation.iY = maze_data_H[i][1];
        ptRegionIn1.tSize.iWidth = maze_data_H[i][2] - maze_data_H[i][0];
        if(arm_2d_region_intersect(   
                            &ptRegionIn0,
                            &ptRegionIn1,
                            &ptRegionOut)){
            green_line_H[j++] = i+1;
        }
    }
    j = 0;
    ptRegionIn1.tSize.iWidth = MAZE_LINE_WIDTH_HIGH;
    for(i = 0;  i < MAZE_DATA_L_NUM; i++){
        ptRegionIn1.tLocation.iX = maze_data_L[i][0];
        ptRegionIn1.tLocation.iY = maze_data_L[i][1];
        ptRegionIn1.tSize.iHeight = maze_data_L[i][2] - maze_data_L[i][1];
        if(arm_2d_region_intersect(   
                            &ptRegionIn0,
                            &ptRegionIn1,
                            &ptRegionOut)){
            green_line_L[j++] = i+1;
        }
    }
    
}
char check_colliding_line_stop(const arm_2d_region_t *ptRegionIn0){
    char i = 0;
    arm_2d_region_t ptRegionIn1 = {.tLocation = {.iX = 0,.iY = 0,},.tSize = {.iWidth = 0, .iHeight = MAZE_LINE_WIDTH_HIGH  }};
    arm_2d_region_t ptRegionOut;
    for(i = 0;  i < 10; i++){
        if(green_line_H[i]){
            ptRegionIn1.tLocation.iX = maze_data_H[green_line_H[i] - 1][0];
            ptRegionIn1.tLocation.iY = maze_data_H[green_line_H[i] - 1][1];
            ptRegionIn1.tSize.iWidth = maze_data_H[green_line_H[i] - 1][2] - maze_data_H[green_line_H[i] - 1][0];
            if(arm_2d_region_intersect(   
                                ptRegionIn0,
                                &ptRegionIn1,
                                &ptRegionOut)){
                //people_moving_direction = 0;                    
                return 1;
            }
        }
    }
    ptRegionIn1.tSize.iWidth = MAZE_LINE_WIDTH_HIGH;
    for(i = 0;  i < 10; i++){
        if(green_line_L[i]){
            ptRegionIn1.tLocation.iX = maze_data_L[green_line_L[i] - 1][0];
            ptRegionIn1.tLocation.iY = maze_data_L[green_line_L[i] - 1][1];
            ptRegionIn1.tSize.iHeight = maze_data_L[green_line_L[i] - 1][2] - maze_data_L[green_line_L[i] - 1][1];
            if(arm_2d_region_intersect(   
                                ptRegionIn0,
                                &ptRegionIn1,
                                &ptRegionOut)){
                // people_moving_direction = 0;                    
                return 1;
            }
        }
    }
    return 0;
}
char intersection_flag = 0; //left right up down
char check_intersection_stop(){
    arm_2d_region_t leftRegion =  {.tLocation = {.iX = 0,.iY = 0,},.tSize = {.iWidth = MAZE_LINE_WIDTH_HIGH + MAZE_PEOPLE_WIDTH, .iHeight = MAZE_PEOPLE_WIDTH }};
    arm_2d_region_t rightRegion =  {.tLocation = {.iX = 0,.iY = 0,},.tSize = {.iWidth = MAZE_LINE_WIDTH_HIGH + MAZE_PEOPLE_WIDTH, .iHeight = MAZE_PEOPLE_WIDTH }};
    arm_2d_region_t upRegion =  {.tLocation = {.iX = 0,.iY = 0,},.tSize = {.iWidth = MAZE_PEOPLE_WIDTH, .iHeight =MAZE_LINE_WIDTH_HIGH + MAZE_PEOPLE_WIDTH }};
    arm_2d_region_t downRegion =  {.tLocation = {.iX = 0,.iY = 0,},.tSize = {.iWidth = MAZE_PEOPLE_WIDTH, .iHeight =MAZE_LINE_WIDTH_HIGH + MAZE_PEOPLE_WIDTH }};
    switch(people_moving_direction){
        case PIN_DIRECTION_DOWN:
            case PIN_DIRECTION_UP:
                leftRegion.tLocation.iX =  tPeopleRegion.tLocation.iX - leftRegion.tSize.iWidth; 
                leftRegion.tLocation.iY =  tPeopleRegion.tLocation.iY;
                if(check_colliding_line_stop(&leftRegion)){
                     intersection_flag &= (~0x01);       
                }else{
                    if(leftRegion.tLocation.iX > 0){
                        intersection_flag |= (0x01);
                    }else{
                        intersection_flag &= (~0x01);  
                    }                        
                }
                rightRegion.tLocation.iX = tPeopleRegion.tLocation.iX + MAZE_PEOPLE_WIDTH;
                rightRegion.tLocation.iY =  tPeopleRegion.tLocation.iY;
                if(check_colliding_line_stop(&rightRegion)){
                     intersection_flag &= (~0x02);       
                }else{
                    if(rightRegion.tLocation.iX > (240 - rightRegion.tSize.iWidth)){
                        intersection_flag &= (~0x02);  
                    }else{
                        intersection_flag |= (0x02);
                    }
                }
                if(intersection_flag & 0x03){
                    people_moving_direction = 0;
                    return 1;
                }
            break;
                
            case  PIN_DIRECTION_LEFT:
                case  PIN_DIRECTION_RIGHT:
                    upRegion.tLocation.iX = tPeopleRegion.tLocation.iX;
                    upRegion.tLocation.iY = tPeopleRegion.tLocation.iY - upRegion.tSize.iHeight;
                    if(check_colliding_line_stop(&upRegion)){
                         intersection_flag &= (~0x04);       
                    }else{
                        if(upRegion.tLocation.iY > 0){
                            intersection_flag |= (0x04);
                        }else{
                            intersection_flag &= (~0x04);  
                        }                        
                    }
                    downRegion.tLocation.iX = tPeopleRegion.tLocation.iX;
                    downRegion.tLocation.iY = tPeopleRegion.tLocation.iY + MAZE_PEOPLE_WIDTH;
                    if(check_colliding_line_stop(&downRegion)){
                         intersection_flag &= (~0x08);       
                    }else{
                        if(downRegion.tLocation.iY > (240 - downRegion.tSize.iHeight)){
                            intersection_flag &= (~0x08);  
                        }else{
                            intersection_flag |= (0x08);
                        }
                    }
                    if(intersection_flag & 0x0c){
                        people_moving_direction = 0;
                        return 1;
                    }
                    break; 
            
        
    }
    return 0;
}
void maze_key_progress(char key){
    
    if(key){
        people_moving_direction = key;
    }
    
    switch(people_moving_direction){
        case PIN_DIRECTION_LEFT:
            if(tPeopleRegion.tLocation.iX > 0){
                tPeopleRegion.tLocation.iX--;  
                if(check_colliding_line_stop(&tPeopleRegion)){
                    people_moving_direction = 0;
                    tPeopleRegion.tLocation.iX++;
                }
            }                
        break;
        case PIN_DIRECTION_RIGHT:
            if(tPeopleRegion.tLocation.iX < (240-MAZE_PEOPLE_WIDTH)){
                tPeopleRegion.tLocation.iX++;   
                if(check_colliding_line_stop(&tPeopleRegion)){
                    people_moving_direction = 0;
                    tPeopleRegion.tLocation.iX--;
                }
            }
        break;
        case PIN_DIRECTION_DOWN:
            if(tPeopleRegion.tLocation.iY < (240-MAZE_PEOPLE_WIDTH)){
                tPeopleRegion.tLocation.iY++;
                if(check_colliding_line_stop(&tPeopleRegion)){
                    people_moving_direction = 0;
                    tPeopleRegion.tLocation.iY--;
                }
            }
        break;
        case PIN_DIRECTION_UP:
            if(tPeopleRegion.tLocation.iY > 0){
                tPeopleRegion.tLocation.iY--;
                if(check_colliding_line_stop(&tPeopleRegion)){
                    people_moving_direction = 0;
                    tPeopleRegion.tLocation.iY++;
                }
            }
        break;
    }
    

}

void maze_play_task(arm_2d_scene_t *ptScene){    
    char key = 0;
    static char flag = 0;
    static char time = 0;
    //key = get_key();
    if(key_num){
        //set_key_num(0);
			  key = key_num;
			  key_num = 0;
    }
    switch(flag){
        case 0:
            flag = 1;
            time = 0;
            //break;
        case 1:
            maze_key_progress(key);
            if(check_intersection_stop()){
                flag = 2;
            }  
        break;
        case 2:
            if((key == PIN_DIRECTION_LEFT) || (key == PIN_DIRECTION_RIGHT) || (key == PIN_DIRECTION_DOWN) ||(key == PIN_DIRECTION_UP) ){
                intersection_flag = 0;
                flag = 3;
            }else{
                break;
            }    
        //break;
        case 3:
            maze_key_progress(key);
            time++;
            if(time > 10){
                flag = 0;
            }
        break;
    
    }
    find_maze_line();
    
    if(key == PIN_DIRECTION_KEY_A){
        tPeopleRegion.tLocation.iX = 220;
        tPeopleRegion.tLocation.iY = 2;
        intersection_flag = 0;
        __arm_2d_scene1_init(&DISP0_ADAPTER,NULL);
        arm_2d_scene_player_switch_to_next_scene(ptScene->ptPlayer);
    }
    
}


void draw_my_maze(void *pTarget,                                  
                 const arm_2d_tile_t *ptTile,                   
                 bool bIsNewFrame){
		 do{//green_line_H
        char i = 0;
        arm_2d_region_t t_L_Line = {
                .tLocation = {3,3},
                .tSize = {MAZE_LINE_WIDTH_HIGH, 178},
        };

        arm_2d_region_t t_H_Line = {
                .tLocation = {3,3},
                .tSize = {15, MAZE_LINE_WIDTH_HIGH},
        };
        
        for(i = 0; i < 10; i++){
			if(green_line_H[i])	{
				t_H_Line.tLocation.iX = maze_data_H[green_line_H[i] - 1][0];
				t_H_Line.tLocation.iY = maze_data_H[green_line_H[i] - 1][1];
				t_H_Line.tSize.iWidth = maze_data_H[green_line_H[i] - 1][2] - maze_data_H[green_line_H[i] - 1][0];
				arm_2d_rgb16_fill_colour(ptTile, &t_H_Line, GLCD_COLOR_GREEN);
            }                
		}
		for(i = 0; i < 10; i++){
            if(green_line_L[i])	{
				t_L_Line.tLocation.iX = maze_data_L[green_line_L[i] - 1][0];
				t_L_Line.tLocation.iY = maze_data_L[green_line_L[i] - 1][1];
				t_L_Line.tSize.iHeight = maze_data_L[green_line_L[i] - 1][2] - maze_data_L[green_line_L[i] - 1][1];
				arm_2d_rgb16_fill_colour(ptTile, &t_L_Line, GLCD_COLOR_GREEN);	
            }
		}
    }while(0);
    do{
        arm_2d_region_t tBox_Bright={.tLocation = {.iX = 200,.iY = 0,},.tSize = {.iWidth = 10, .iHeight = 10  },};
        tBox_Bright.tLocation.iX = 0;
		tBox_Bright.tLocation.iY = 0;
		tBox_Bright.tSize.iWidth = tPeopleRegion.tLocation.iX - R_BRIGHT;
		tBox_Bright.tSize.iHeight = 240;
		arm_2d_rgb16_fill_colour(ptTile, &tBox_Bright, R_BRIGHT_COLOR );
        //arm_2dp_fill_colour_with_opacity(NULL,ptTile,&tBox_Bright,(__arm_2d_color_t){R_BRIGHT_COLOR},155);
		
		tBox_Bright.tLocation.iX = tPeopleRegion.tLocation.iX - R_BRIGHT;
		tBox_Bright.tLocation.iY = tPeopleRegion.tLocation.iY + MAZE_PEOPLE_WIDTH + R_BRIGHT;
		tBox_Bright.tSize.iWidth = 240 - tBox_Bright.tLocation.iX;
		tBox_Bright.tSize.iHeight = 240 - tBox_Bright.tLocation.iY;
		arm_2d_rgb16_fill_colour(ptTile, &tBox_Bright, R_BRIGHT_COLOR );
        //arm_2dp_fill_colour_with_opacity(NULL,ptTile,&tBox_Bright,(__arm_2d_color_t){R_BRIGHT_COLOR},155);
		
		tBox_Bright.tLocation.iX = tPeopleRegion.tLocation.iX - R_BRIGHT;   //shang bian
		tBox_Bright.tLocation.iY = 0;
		tBox_Bright.tSize.iWidth = 240 - tBox_Bright.tLocation.iX;
		tBox_Bright.tSize.iHeight = tPeopleRegion.tLocation.iY - R_BRIGHT; ;
		arm_2d_rgb16_fill_colour(ptTile, &tBox_Bright, R_BRIGHT_COLOR );
        //arm_2dp_fill_colour_with_opacity(NULL,ptTile,&tBox_Bright,(__arm_2d_color_t){R_BRIGHT_COLOR},155);
		
		tBox_Bright.tLocation.iX = tPeopleRegion.tLocation.iX  + MAZE_PEOPLE_WIDTH + R_BRIGHT;   //you bian
		tBox_Bright.tLocation.iY = tPeopleRegion.tLocation.iY - R_BRIGHT;
		tBox_Bright.tSize.iWidth = 240 - tBox_Bright.tLocation.iX;
		tBox_Bright.tSize.iHeight = R_BRIGHT + R_BRIGHT  + MAZE_PEOPLE_WIDTH; 
		arm_2d_rgb16_fill_colour(ptTile, &tBox_Bright, R_BRIGHT_COLOR );
        //arm_2dp_fill_colour_with_opacity(NULL,ptTile,&tBox_Bright,(__arm_2d_color_t){R_BRIGHT_COLOR},155);
		
		tBox_Bright.tLocation.iX = 0;   //
		tBox_Bright.tLocation.iY = 220;
		tBox_Bright.tSize.iWidth = 16;
		tBox_Bright.tSize.iHeight = 20; 
		arm_2d_rgb16_fill_colour(ptTile, &tBox_Bright, MAZE_EXIT_COLOR );
    
    }while(0);
    
    do{
        arm_2d_rgb16_fill_colour(ptTile, &tPeopleRegion, PEOPLE_COLOR );
    }while(0);
    
    do{//intersection_flag = 0; //left right up down
        arm_2d_region_t tBox_region={.tLocation = {.iX = 0,.iY = 0,},.tSize = {.iWidth = 15, .iHeight = 10  },};
        //left
        if(intersection_flag & 0x01){
            tBox_region.tLocation.iX =  tPeopleRegion.tLocation.iX - tBox_region.tSize.iWidth; 
            tBox_region.tLocation.iY =  tPeopleRegion.tLocation.iY;
            arm_2d_rgb16_fill_colour(ptTile, &tBox_region, MAZE_INTERSECTION_COLOR );
        }
        //right
        if(intersection_flag & 0x02){
            tBox_region.tLocation.iX = tPeopleRegion.tLocation.iX + MAZE_PEOPLE_WIDTH;
            tBox_region.tLocation.iY =  tPeopleRegion.tLocation.iY;
            arm_2d_rgb16_fill_colour(ptTile, &tBox_region, MAZE_INTERSECTION_COLOR );
        }
        
        tBox_region.tSize.iWidth = 10;
        tBox_region.tSize.iHeight= 15;
        //up
        if(intersection_flag & 0x04){
            tBox_region.tLocation.iX = tPeopleRegion.tLocation.iX;
            tBox_region.tLocation.iY = tPeopleRegion.tLocation.iY - tBox_region.tSize.iHeight;
            arm_2d_rgb16_fill_colour(ptTile, &tBox_region, MAZE_INTERSECTION_COLOR );
        }
        //down
        if(intersection_flag & 0x08){
            tBox_region.tLocation.iX = tPeopleRegion.tLocation.iX;
            tBox_region.tLocation.iY = tPeopleRegion.tLocation.iY + MAZE_PEOPLE_WIDTH;
            arm_2d_rgb16_fill_colour(ptTile, &tBox_region, MAZE_INTERSECTION_COLOR );
        }
    
    }while(0);							 
}


#if defined(__clang__)
#   pragma clang diagnostic pop
#endif

#endif

#endif

